# -*- coding: utf-8 -*-

import json
from dify_client import ChatClient

api_key = ""

# Initialize ChatClient
chat_client = ChatClient(api_key)
chat_client.base_url = "http://121.40.227.217/v1"

# Create Chat Message using ChatClient
conversation_id = "961ab6ea-39a6-494d-9778-a81d2eb674d4"
chat_response = chat_client.create_chat_message(inputs={}, query="阿米娜和酒馆老板关系如何", user="user_id", 
                                                response_mode="streaming", conversation_id=conversation_id)
chat_response.raise_for_status()

for line in chat_response.iter_lines(decode_unicode=True):
    line = line.split('data:', 1)[-1]
    if line.strip():
        try:
            line = json.loads(line.strip())
            print(line.get('answer'))
        except Exception as e:
            pass